//
//  SearchViewController.m
//  TodatPlay
//
//  Created by dllo on 16/9/19.
//  Copyright © 2016年 DM.C. All rights reserved.
//

#import "SearchViewController.h"
#import "SearchCollectionViewCell.h"
#import "TAMacro.h"
#import "CollectionReusableView.h"

#define kCOllectionViewCellReuse @"reuse"
#define kCOllectionViewHeaderReuse @"headerResue"
@interface SearchViewController ()<UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
@property (weak, nonatomic) IBOutlet UICollectionView *searchCollectionVIew;
@property (weak, nonatomic) IBOutlet UICollectionViewFlowLayout *searchFlowLayout;


@end

@implementation SearchViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self.searchCollectionVIew registerNib:[UINib nibWithNibName:@"SearchCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:kCOllectionViewCellReuse];
    [self.searchCollectionVIew registerClass:[CollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:kCOllectionViewHeaderReuse];
    self.searchFlowLayout.sectionInset = UIEdgeInsetsMake(10, 5, 10, 5);
    self.searchFlowLayout.minimumLineSpacing = 5;
    self.searchFlowLayout.minimumInteritemSpacing = 0;
    
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 3;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 8;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    SearchCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kCOllectionViewCellReuse forIndexPath:indexPath];
    
    cell.label.text = @"演唱会";
    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    CGFloat width = (SCREEN_WIDTH - 20) / 4.0;
    
    return CGSizeMake(width, 20);
}
- (UICollectionReusableView *) collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
   
    if (indexPath.section == 0) {
        CollectionReusableView *reuseable = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:kCOllectionViewHeaderReuse forIndexPath:indexPath];
        reuseable.titleLabel.text = @"一周关键词";
        return reuseable;

    } else if (indexPath.section == 1) {
        CollectionReusableView *reuseable = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:kCOllectionViewHeaderReuse forIndexPath:indexPath];
        reuseable.titleLabel.text = @"精选关键词";
        return reuseable;

    } else {
        CollectionReusableView *reuseable = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:kCOllectionViewHeaderReuse forIndexPath:indexPath];
        reuseable.titleLabel.text = @"搜索记录";
        return reuseable;
    }
    
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
    return CGSizeMake(SCREEN_WIDTH, 44);
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
